Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the BlogPosts class.
	''' </summary>
	<Serializable> _
	Public Partial Class BlogPostsCollection 
	Inherits ActiveList(Of BlogPosts, BlogPostsCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the BlogPosts table.
	''' </summary>
	<Serializable> _
	Public Partial Class BlogPosts 
	Inherits ActiveRecord(Of BlogPosts)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("BlogPosts", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarPostid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarPostid.ColumnName = "postid"
                colvarPostid.DataType = DbType.Int32
                colvarPostid.MaxLength = 0
                colvarPostid.AutoIncrement = true
                colvarPostid.IsNullable = false
                colvarPostid.IsPrimaryKey = true
                colvarPostid.IsForeignKey = false
                colvarPostid.IsReadOnly = false
                
                
                schema.Columns.Add(colvarPostid)
                
                Dim colvarTitle As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarTitle.ColumnName = "Title"
                colvarTitle.DataType = DbType.String
                colvarTitle.MaxLength = 800
                colvarTitle.AutoIncrement = false
                colvarTitle.IsNullable = false
                colvarTitle.IsPrimaryKey = false
                colvarTitle.IsForeignKey = false
                colvarTitle.IsReadOnly = false
                
                
                schema.Columns.Add(colvarTitle)
                
                Dim colvarPostText As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarPostText.ColumnName = "PostText"
                colvarPostText.DataType = DbType.String
                colvarPostText.MaxLength = 8000
                colvarPostText.AutoIncrement = false
                colvarPostText.IsNullable = false
                colvarPostText.IsPrimaryKey = false
                colvarPostText.IsForeignKey = false
                colvarPostText.IsReadOnly = false
                
                
                schema.Columns.Add(colvarPostText)
                
                Dim colvarPostdate As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarPostdate.ColumnName = "postdate"
                colvarPostdate.DataType = DbType.DateTime
                colvarPostdate.MaxLength = 0
                colvarPostdate.AutoIncrement = false
                colvarPostdate.IsNullable = false
                colvarPostdate.IsPrimaryKey = false
                colvarPostdate.IsForeignKey = false
                colvarPostdate.IsReadOnly = false
                
                
                schema.Columns.Add(colvarPostdate)
                
                Dim colvarMemid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarMemid.ColumnName = "memid"
                colvarMemid.DataType = DbType.Guid
                colvarMemid.MaxLength = 0
                colvarMemid.AutoIncrement = false
                colvarMemid.IsNullable = false
                colvarMemid.IsPrimaryKey = false
                colvarMemid.IsForeignKey = false
                colvarMemid.IsReadOnly = false
                
                
                schema.Columns.Add(colvarMemid)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("BlogPosts",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("Postid")> _
        Public Property Postid As Integer 
			Get
				Return GetColumnValue(Of Integer)("postid")
			End Get
		    
			Set
				SetColumnValue("postid", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Title")> _
        Public Property Title As String 
			Get
				Return GetColumnValue(Of String)("Title")
			End Get
		    
			Set
				SetColumnValue("Title", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("PostText")> _
        Public Property PostText As String 
			Get
				Return GetColumnValue(Of String)("PostText")
			End Get
		    
			Set
				SetColumnValue("PostText", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Postdate")> _
        Public Property Postdate As DateTime 
			Get
				Return GetColumnValue(Of DateTime)("postdate")
			End Get
		    
			Set
				SetColumnValue("postdate", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Memid")> _
        Public Property Memid As Guid 
			Get
				Return GetColumnValue(Of Guid)("memid")
			End Get
		    
			Set
				SetColumnValue("memid", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
		
		
		
		
		
	    
	    'no foreign key tables defined (0)
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varTitle As String,ByVal varPostText As String,ByVal varPostdate As DateTime,ByVal varMemid As Guid)
			Dim item As BlogPosts = New BlogPosts()
			
            item.Title = varTitle
            
            item.PostText = varPostText
            
            item.Postdate = varPostdate
            
            item.Memid = varMemid
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varPostid As Integer,ByVal varTitle As String,ByVal varPostText As String,ByVal varPostdate As DateTime,ByVal varMemid As Guid)
			Dim item As BlogPosts = New BlogPosts()
		    
                item.Postid = varPostid
				
                item.Title = varTitle
				
                item.PostText = varPostText
				
                item.Postdate = varPostdate
				
                item.Memid = varMemid
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared Postid As String = "postid"
            
            Public Shared Title As String = "Title"
            
            Public Shared PostText As String = "PostText"
            
            Public Shared Postdate As String = "postdate"
            
            Public Shared Memid As String = "memid"
            
		End Structure
		#End Region
	End Class
End Namespace
